********************************************************************************
* Dataanalysis: All dataanalysis for the concurrent election project ***********
********************************************************************************

cls
clear all
clear matrix
set more off
capture log close

log using "C:/Userdata/Shared/Logs/Concurrent elections/dataanalysis.text", replace text 

cd "C:/Userdata/Shared/Dofiles/"

* Path directories*
global dodatadf "DoData/Concurrent elections"									// DoData dofiles
global doanalysisdf "DoAnalysis/Concurrent elections"							// Doanalysis dofiles
global usingdata "E:/ProjData/Concurrent elections/"							// Using data directory
global rawdata "D:/SCB_ConPol/Stata"											// Raw data directory
global output "C:/Userdata/Shared/Output/Concurrent elections"					// Output directory	
do "$dodatadf/programs.do"		


********************************************************************************
* LOAD MAIN DATA SET************************************************************
********************************************************************************

use "$usingdata/finaldata/finaldata_immigrants.dta", clear
replace days_treat_enrolled=days_treat_enrolled * (-1)							// See comment above
replace days_treat_citizen=days_treat_citizen * (-1)							


* Esttab setup*
global esttab "replace label se nogaps b(3) compress nostar booktabs nonotes varlabels(_cons "Constant")"

* Covariates macros *
global ICovs "age bigcity children sex ehat_yeduc welf ehat_pre_ink ehat_pre_emp africa asia europe southam time_in_country"
global ICovswithoutorigin "age bigcity children sex ehat_yeduc welf ehat_pre_ink ehat_pre_emp time_in_country"


********************************************************************************
* CHECKING INTERVAL VALIDITY, cont. Main years *********************************
********************************************************************************

** Eligibility graphs according to Calonico et al (2015) **

* 1994, with donut*
rdplot eligeble days_treat_enrolled if (days_treat_enrolled > 0 | days_treat_enrolled <-7) & year_ctz == 1994, ///
graph_options(name(g1, replace) legend(off)graphregion(color(white)) title("") ytitle("Eligibility") xtitle("Running variable") xline(79, lcolor(gs8)))
graph export "$output/img/rdplot_eligibility1994_1.pdf", replace

* 2010, with donut *
rdplot eligeble days_treat_enrolled if (days_treat_enrolled > 0 | days_treat_enrolled <-7) & year_ctz == 2010, ///
graph_options(name(g2, replace) legend(off)graphregion(color(white)) title("") ytitle("Eligibility") xtitle("Running variable") xline(30, lcolor(gs8)))
graph export "$output/img/rdplot_eligibility2010_1.pdf", replace

* 1994, without donut *
rdplot eligeble days_treat_enrolled if year_ctz == 1994, ///
graph_options(name(g3, replace) legend(off)graphregion(color(white)) title("") ytitle("Eligibility") xtitle("Running variable") xline(79, lcolor(gs8)))
graph export "$output/img/rdplot_eligibility1994_2.pdf", replace

*2010, without donut *
rdplot eligeble days_treat_enrolled if year_ctz == 2010, ///
graph_options(name(g4, replace) legend(off) graphregion(color(white)) title("") ytitle("Eligibility") xtitle("Running variable") xline(30, lcolor(gs8)))
graph export "$output/img/rdplot_eligibility2010_2.pdf", replace

graph combine g3 g4 g1 g2, graphregion(color(white))
graph export "$output/img/rdplot_eligibility1994_2010.pdf", replace


********************************************************************************
* NUMBERS OF OBSERVATIONS (values used in the text)*****************************
********************************************************************************

file open observations using "$output/tex/observations.txt", write replace
sum LopNr 
file write observations "Obs Total: `r(N)'" _n	

sum LopNr if year_ctz == 2010 
file write observations "Obs 2010: `r(N)'" _n	

sum LopNr if year_ctz == 1994 
file write observations "Obs 1994: `r(N)'" _n

file close observations


********************************************************************************
* RD PLOTS *********************************************************************
********************************************************************************

* RD-plot according to Calonico et al (2015): Only salience, 1994
rdplot voted_local days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 1994, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout") xtitle("Running variable") xline(79, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_1994.pdf", replace

* [...] Only salience, 2010 *
rdplot voted_local days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 2010, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout") xtitle("Running variable") xline(30, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_2010.pdf", replace

* [...] Only timing of citizenship, 1994 *
rdplot voted_local days_treat_citizen if (days_treat_citizen >= 0 | days_treat_citizen <-7) & year_ctz == 1994, graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout") xtitle("Running variable")), 
graph export "$output/img/rdplotT1T2_1994.pdf", replace

* [...] Only timing of citizenship, 2010 *
rdplot voted_local days_treat_citizen if (days_treat_citizen >= 0 | days_treat_citizen <-7) & year_ctz == 2010, graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout") xtitle("Running variable")), 
graph export "$output/img/rdplotT1T2_2010.pdf", replace

/* Observe 1: We include a gray line in the first two graphs to indicate the date of the citizenship treatment.*/
/* The citienship treatment is then plotted separately in the last two graphs */
/* Observe 2: The donut window is depending how the running variable is scaled (to faciliate for the reader). Therefore, the specification is changed below for the regressions. This does not alter the interpretation.*/

********************************************************************************
* OPTIMAL BANDWIDTH CALCULATIONS SALIENCE EFFECT (numbers used in the text) ****
********************************************************************************

replace days_treat_enrolled=days_treat_enrolled * (-1)							/*The RDrobust and RDbwselect packages must have positive values of running variable = treatment. We therefore change back to the intitial specification of the running variable. This does not change anything in the interpretation */

file open optbandwidth using "$output/tex/bw.txt", write replace
rdbwselect voted_local days_treat_enrolled, kernel(uniform) all					/*Uniform kernel as in the regressions*/				
file write optbandwidth "BW all observations, both years: `e(h_mserd)'"
rdbwselect voted_local days_treat_enrolled if year_ctz == 1994, kernel(uniform) all					
file write optbandwidth "BW 1994: `e(h_mserd)'"
rdbwselect voted_local days_treat_enrolled if year_ctz == 2010, kernel(uniform) all					
file write optbandwidth "BW 2010 symmetric: `e(h_mserd)'"
rdbwselect voted_local days_treat_enrolled if year_ctz == 2010, kernel(uniform) all					
file write optbandwidth "BW 2010 assymetric below: `e(h_msetwo_l)'"
rdbwselect voted_local days_treat_enrolled if year_ctz == 2010, kernel(uniform) all					
file write optbandwidth "BW 2010 assymetric above: `e(h_msetwo_r)'"
file close optbandwidth


********************************************************************************
* MAIN REGRESSION ANALYSIS: SALIENCE EFFECT (T2 versus T3)**********************
********************************************************************************

/*Observe: All results are presented for multiple bandwidths in graphs*/



** 1994 **

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {															// OBS: 10 including the donut equals a window of 3 days of the running variable above the cut-off. 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												// Conventional standard errors												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1, lpattern(dash) lcolor(gs8)) (line rd4 rd1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) ylabel(-0.4(0.1)0.4) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/main_bandbreddgraf_1994.pdf", replace 
restore
drop rd*


* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform) fuzzy(eligeble)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1, lpattern(dash) lcolor(gs8)) (line rd4 rd1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) ylabel(-0.6(0.1)0.6) legend(order(1 "Point estimate fuzzy RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/main_fuzzybandbreddgraf_1994.pdf", replace 
restore
drop rd*


** 2010 **

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {															/*Observe that we vary the upper bandwidth in the case of 2010. The lower bandwidth cannot be larger than 30*/
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1, lpattern(dash) lcolor(gs8)) (line rd4 rd1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) ylabel(-0.2(0.1)0.2) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/main_bandbreddgraf_2010.pdf", replace 
restore
drop rd*


* Fuzzy estimate with donut *
clear matrix							
forvalues k = 11(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform) fuzzy(eligeble)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1, lpattern(dash) lcolor(gs8)) (line rd4 rd1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) ylabel(-0.8(0.1)0.7) legend(order(1 "Point estimate fuzzy RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/main_fuzzybandbreddgraf_2010.pdf", replace 
restore
drop rd*




/*Observe 1: Positive values of running variable indicate treatment. Above the cut-off = positive values = earlier dates in the calendrar year */
/*Observe 2: The chosen bandwiths of the running variable ensures that we do not include anyone from the middle group who are cititizens but without the right to vote.*/


********************************************************************************
* THE PURE CITIZENSHIP EFFECT (APPENDIX) (T1 versus T2) ************************
********************************************************************************

replace days_treat_citizen = days_treat_citizen * (-1)							// See earlier comment

* Optimal bandwidths calculations *
file open optbandwidthcitizen using "$output/tex/optbandwidthcitizen.txt", write replace
rdbwselect voted_local days_treat_citizen, kernel(uniform) all					
file write optbandwidthcitizen "BW all observations, both years: `e(h_mserd)'"
rdbwselect voted_local days_treat_citizen if year_ctz == 1994, kernel(uniform) all					
file write optbandwidthcitizen "BW 1994: `e(h_mserd)'"
rdbwselect voted_local days_treat_citizen if year_ctz == 2010, kernel(uniform) all					
file write optbandwidthcitizen "BW 2010 symmetric: `e(h_mserd)'"
rdbwselect voted_local days_treat_citizen if year_ctz == 2010, kernel(uniform) all					
file write optbandwidthcitizen "BW 2010 assymetric below: `e(h_msetwo_l)'"
rdbwselect voted_local days_treat_citizen if year_ctz == 2010, kernel(uniform) all					
file write optbandwidthcitizen "BW 2010 assymetric above: `e(h_msetwo_r)'"
file close optbandwidthcitizen


** 1994 **

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)78 {															// 78 days so that the window does not overlap with the salience treatment. 
	preserve
	rdrobust voted_local days_treat_citizen if (days_treat_citizen > 7 | days_treat_citizen <=0) & year_ctz == 1994, h(`k') kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1,  lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/t1t2_bandbreddgraf_1994.pdf", replace 
restore
drop rd*

** 2010 **

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)78 {															/*29 for the lower bandwidth so that we do not overlap with the salience treatment window.*/
	preserve
	rdrobust voted_local days_treat_citizen if (days_treat_citizen > 7 | days_treat_citizen <=0) & year_ctz == 2010, h(`k' 29) kernel(uniform)     
	matrix define a=e(b)																							/*Observe: Changed order in comparison to salience effect. The treatment window of 29 days is earlier in the calendar year = above cut-off = before the election*/													
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1,  lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, below cut-off")
graph export "$output/img/t1t2_bandbreddgraf_2010.pdf", replace 
restore
drop rd*

/* Observe 1: We choose the same donut window as for the salience analysis, but for the citizenship cut-off*/
/* Observe 2: No fuzzy estimates in this case since citizenship cannot be instrumented in itself*/


********************************************************************************
* ROBUSTNESS ANALYSIS***********************************************************
********************************************************************************

*** Sharp estimates with donut ***


** Main results, but with covariates **

* 1994 *

clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform) covs($ICovs)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/covs_bandbreddgraf_1994.pdf", replace 
restore
drop rd*




* 2010 *

clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform) covs($ICovs)    
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/covs_bandbreddgraf_2010.pdf", replace 
restore
drop rd*



** Donut graphs **

*1994*
clear matrix
forvalues k = 1(1)14 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled >= `k' | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(1(1)14) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Donut upper limit (days removed from cut-off). Bandwidth 79 days.")
graph export "$output/img/donutgraph_1994.pdf", replace 
restore
drop rd*

*2010*
clear matrix
forvalues k = 1(1)14 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled >= `k' | days_treat_enrolled <=0) & year_ctz == 2010, h(30) kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(1(1)14) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Donut upper limit (days removed from cut-off). Bandwidth 30 days.")
graph export "$output/img/donutgraph_2010.pdf", replace 
restore
drop rd*




** Small symmetric bandwidth graph below 30, 2010, main specification**
clear matrix
forvalues k = 10(1)30 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(`k') kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(10(2)30) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/bandbreddgrafsmall_2010.pdf", replace 
restore
drop rd*

** Triangular kernel **

*1994*
clear matrix
forvalues k = 11(1)79 {															/*Observe that triangular kernel is benchmark setting for rdrobust*/
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k')      
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/bandbreddgraftriangular_1994.pdf", replace 
restore
drop rd*

*2010*
clear matrix
forvalues k = 10(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k')     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/bandbreddgraftriangular_2010.pdf", replace 
restore
drop rd*


** Quadratic polynomials **

*1994*
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform) p(2)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/bandbreddgrafquad_1994.pdf", replace 
restore
drop rd*

*2010*
clear matrix
forvalues k = 10(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform) p(2)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/bandbreddgrafquad_2010.pdf", replace 
restore
drop rd*


** Bias corrected robust confidence intervals according to Calonico et al (2014) **

/*Observe: Calonico et al separate between point estimation and inference. Therefore, bias corrected robust C.I.'s does not have a point estimate in the figures*/

*1994*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform)     
	matrix define c1=e(ci_l_rb)													// Only confidence intervals in this case.
	matrix define c2=e(ci_r_rb)
	scalar define e1=(c1[1,1])	
	scalar define e2=(c2[1,1])
	scalar define upper=e2												
	scalar define lower=e1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,lower,upper]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd3 rd1 if rd3>=-1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4<=1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "95 % bias corrected robust CI") region(col(white))) ytitle("Estimated C.I.") xtitle("Symmetric bandwidth in days")
graph export "$output/img/bandbreddgraf_1994_robustCI.pdf", replace 
restore
drop rd*

*2010*
clear matrix
forvalues k = 10(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform)     
	matrix define c1=e(ci_l_rb)
	matrix define c2=e(ci_r_rb)
	scalar define e1=(c1[1,1])	
	scalar define e2=(c2[1,1])
	scalar define upper=e2												
	scalar define lower=e1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,lower,upper]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd3 rd1 if rd3>=-1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4<=1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "95 % bias corrected robust CI") region(col(white))) ytitle("Estimated C.I.") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/bandbreddgraf_robustCI_2010.pdf", replace 
restore
drop rd*




*** Fuzzy estimates with donut ***

** Main analysis, but with covariates **

* 1994 *
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform) fuzzy(eligeble) covs($ICovs)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/covs_fuzzybandbreddgraf_1994.pdf", replace 
restore
drop rd*

* 2010*
clear matrix							
forvalues k = 10(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform) fuzzy(eligeble) covs($ICovs)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/covs_fuzzybandbreddgraf_2010.pdf", replace 
restore
drop rd*



** Donut graphs **

*1994*
clear matrix
forvalues k = 1(1)14 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled >= `k' | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform) fuzzy(eligeble)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(1(1)14) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Donut upper limit (days removed from cut-off). Bandwidth 79 days.")
graph export "$output/img/fuzzydonutgraph_1994.pdf", replace 
restore
drop rd*

*2010*
clear matrix
forvalues k = 1(1)14 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled >= `k' | days_treat_enrolled <=0) & year_ctz == 2010, h(30) kernel(uniform) fuzzy(eligeble)    
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(1(1)14) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Donut upper limit (days removed from cut-off). Bandwidth 30 days.")
graph export "$output/img/fuzzydonutgraph_2010.pdf", replace 
restore
drop rd*


** Small symmetric bandwidth graph below 30, 2010, main specification **
clear matrix
forvalues k = 10(1)30 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(`k') kernel(uniform) fuzzy(eligeble)      
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(10(2)30) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/fuzzybandbreddgrafsmall_2010.pdf", replace 
restore
drop rd*

** Triangular kernel **

*1994*
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') fuzzy(eligeble)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/fuzzybandbreddgraftriangular_1994.pdf", replace 
restore
drop rd*

*2010*
clear matrix
forvalues k = 10(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') fuzzy(eligeble)    
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/fuzzybandbreddgraftriangular_2010.pdf", replace 
restore
drop rd*


** Quadratic polynomials **

*1994*
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform) p(2) fuzzy(eligeble)    
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/fuzzybandbreddgrafquad_1994.pdf", replace 
restore
drop rd*

*2010*
clear matrix
forvalues k = 10(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform) p(2) fuzzy(eligeble)    
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/fuzzybandbreddgrafquad_2010.pdf", replace 
restore
drop rd*


** Bias corrected robust confidence intervals according to Calonico et al (2014) **


*1994*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(`k') kernel(uniform) fuzzy(eligeble)    
	matrix define c1=e(ci_l_rb)													// Only C.I.'s in this case. 											
	matrix define c2=e(ci_r_rb)
	scalar define e1=(c1[1,1])	
	scalar define e2=(c2[1,1])
	scalar define upper=e2												
	scalar define lower=e1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,lower,upper]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd3 rd1 if rd3>=-1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4<=1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "95 % bias corrected robust CI") region(col(white))) ytitle("Estimated C.I.") xtitle("Symmetric bandwidth in days")
graph export "$output/img/bandbreddgraf_1994_robustCI_fuzzy.pdf", replace 
restore
drop rd*

*2010*
clear matrix								
forvalues k = 10(1)79 {
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 `k') kernel(uniform) fuzzy(eligeble)     
	matrix define c1=e(ci_l_rb)
	matrix define c2=e(ci_r_rb)
	scalar define e1=(c1[1,1])	
	scalar define e2=(c2[1,1])
	scalar define upper=e2												
	scalar define lower=e1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,lower,upper]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1==.
graph twoway (line rd3 rd1 if rd3>=-1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4<=1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "95 % bias corrected robust CI") region(col(white))) ytitle("Estimated C.I.") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/bandbreddgraf_2010_robustCI_fuzzy.pdf", replace 
restore
drop rd*


********************************************************************************
* EXTENSIONS *******************************************************************
********************************************************************************


*** Heterogeneity analysis ***

***Regions of origin

*1994*

foreach j in africa asia europe southam {

* Sharp estimates with donut *
clear matrix
forvalues k = 20(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & `j' ==1, h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/`j'_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 20(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & `j' ==1, h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/`j'_1994_fuzzy.pdf", replace 
restore
drop rd*

** 2010 **

*Sharp estimates with donut*
clear matrix
forvalues k = 20(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & `j' ==1, h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/`j'_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 20(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & `j'==1, h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/`j'_2010_fuzzy.pdf", replace 
restore
drop rd*

}




***Regions of origin - with covariates

*1994*

foreach j in africa asia europe southam {

* Sharp estimates with donut *
clear matrix
forvalues k = 20(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & `j' ==1, h(`k') kernel(uniform) covs($ICovswithoutorigin)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/`j'_1994_cov.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 20(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & `j' ==1, h(`k') kernel(uniform) fuzzy(eligeble) covs($ICovswithoutorigin)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/`j'_1994_fuzzy_cov.pdf", replace 
restore
drop rd*

** 2010 **

*Sharp estimates with donut*
clear matrix
forvalues k = 20(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & `j' ==1, h(30 `k') kernel(uniform) covs($ICovswithoutorigin)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/`j'_2010_cov.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 20(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & `j'==1, h(30 `k') kernel(uniform) fuzzy(eligeble) covs($ICovswithoutorigin)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/`j'_2010_fuzzy_cov.pdf", replace 
restore
drop rd*

}


***Large and small enclave


*Large
*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & large_diaspora==1, h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/large_diaspora_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & large_diaspora==1, h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/large_diaspora_1994_fuzzy.pdf", replace 
restore
drop rd*

** 2010 **

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & large_diaspora==1, h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/large_diaspora_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & large_diaspora==1, h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/large_diaspora_2010_fuzzy.pdf", replace 
restore
drop rd*






*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & large_diaspora==0, h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/small_diaspora_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & large_diaspora==0, h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/small_diaspora_1994_fuzzy.pdf", replace 
restore
drop rd*

** 2010 **

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & large_diaspora==0, h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/small_diaspora_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & large_diaspora==0, h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/small_diaspora_2010_fuzzy.pdf", replace 
restore
drop rd*




** Young **

*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & age <=30, h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/young_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & age <=30, h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/young_1994_fuzzy.pdf", replace 
restore
drop rd*

** 2010 **

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & age <=30, h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/young_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & age <=30, h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/young_2010_fuzzy.pdf", replace 
restore
drop rd*


** Old **

*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & age > 30, h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/old_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & age > 30, h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/old_1994_fuzzy.pdf", replace 
restore
drop rd*

* 2010 *

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & age > 30, h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/old_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & age > 30, h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/old_2010_fuzzy.pdf", replace 
restore
drop rd*



** Unemployed **

*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (sysselsatt_09 == 0 | sysselsatt_93 == 0), h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/nojob_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (sysselsatt_09 == 0 | sysselsatt_93 == 0), h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/nojob_1994_fuzzy.pdf", replace 
restore
drop rd*

** 2010 **

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (sysselsatt_09 == 0 | sysselsatt_93 == 0), h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/nojob_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (sysselsatt_09 == 0 | sysselsatt_93 == 0), h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/nojob_2010_fuzzy.pdf", replace 
restore
drop rd*


** Employed **


*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (sysselsatt_09 == 1 | sysselsatt_93 == 1), h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/job_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (sysselsatt_09 == 1 | sysselsatt_93 == 1), h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/job_1994_fuzzy.pdf", replace 
restore
drop rd*

* 2010 *

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (sysselsatt_09 == 1 | sysselsatt_93 == 1), h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/job_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (sysselsatt_09 == 1 | sysselsatt_93 == 1), h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/job_2010_fuzzy.pdf", replace 
restore
drop rd*




** Time in country **

sum time_in_country, d

*One group who has been in the country long before ctz
gen in_time = 1 if time_in_country<=6
replace in_time=0 if time_in_country>6 & time_in_country!=.

*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (in_time == 1), h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/intime_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (in_time == 1), h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/intime_1994_fuzzy.pdf", replace 
restore
drop rd*

* 2010 *

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (in_time == 1), h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/intime_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (in_time == 1), h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/intime_2010_fuzzy.pdf", replace 
restore
drop rd*



*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (in_time == 0), h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/overtime_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (in_time == 0), h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/overtime_1994_fuzzy.pdf", replace 
restore
drop rd*

* 2010 *

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (in_time == 0), h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/overtime_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (in_time == 0), h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/overtime_2010_fuzzy.pdf", replace 
restore
drop rd*





** Analysis without those born in a EU country **

*1994*

* Sharp estimates with donut *
clear matrix
forvalues k = 11(1)79 {		
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (Fodelselandgrp != "EU28 utom Norden"), h(`k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/noEU_1994.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994 & (Fodelselandgrp != "EU28 utom Norden"), h(`k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/noEU_1994_fuzzy.pdf", replace 
restore
drop rd*

* 2010 *

*Sharp estimates with donut*
clear matrix
forvalues k = 11(1)79 {															
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (Fodelselandgrp != "EU28 utom Norden"), h(30 `k') kernel(uniform) 
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/noEU_2010.pdf", replace 
restore
drop rd*

* Fuzzy estimates with donut *
clear matrix
forvalues k = 11(1)79 {															 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010 & (Fodelselandgrp != "EU28 utom Norden"), h(30 `k') kernel(uniform) fuzzy(eligeble)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1 if rd3<=1, lpattern(dash) lcolor(gs8)) (line rd4 rd1 if rd4>=-1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Assymmetric bandwidth in days above the cut-off")
graph export "$output/img/noEU_2010_fuzzy.pdf", replace 
restore
drop rd*




*** Spill-over analysis ***

** RD-plots: Spouses **

replace days_treat_enrolled = days_treat_enrolled * (-1)						// To faciliate for the reader. Changing the donut window below to accomodate. 

* 1994 * 
rdplot voted_local_spouse days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 1994, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout spouse") xtitle("Running variable") xline(79, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_1994_sp.pdf", replace

* 2010 *
rdplot voted_local_spouse days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 2010, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout spouse") xtitle("Running variable") xline(30, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_2010_sp.pdf", replace

** RDplots: Same immigration group in same parish in the same year **

* 1994 *
rdplot turnimmig_local_turnout days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 1994, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("V.t immigrants in parish") xtitle("Running variable") xline(79, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_1994_immig.pdf", replace

* 2010 *
rdplot turnimmig_local_turnout days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 2010, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Vt.t immigrants in parish") xtitle("Running variable") xline(30, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_2010_immig.pdf", replace

replace days_treat_enrolled = days_treat_enrolled * (-1)						// Changing back



********************************************************************************
* BALANCE TESTS COVARIATES******************************************************
********************************************************************************


*** RD-plots ***
replace days_treat_enrolled = days_treat_enrolled * (-1)						// To faciliate for the reader

* Age, bigcity, children, yearseducation, welfare * 
foreach k in age bigcity children ehat_yeduc welf {
	
	*1994*
	rdplot `k' days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 1994, ///
	graph_options(legend(off)graphregion(color(white))title()ytitle("Value covariate") xtitle("Running variable") xline(79, lcolor(gs8))), 
	graph export "$output/img/rdplot_1994_`k'.pdf", replace
	
	*2010*
	rdplot `k' days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 2010, ///
	graph_options(legend(off)graphregion(color(white))title()ytitle("Value covariate") xtitle("Running variable") xline(30, lcolor(gs8))), 
	graph export "$output/img/rdplot_2010_`k'.pdf", replace
}

* Labor market outcomes in t-1 *
foreach k in ehat_pre_ink ehat_pre_emp {
	rdplot `k' days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 2010, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Value covariate") xtitle("Running variable") xline(30, lcolor(gs8))), 
	graph export "$output/img/rdplot_2010_`k'.pdf", replace
}

foreach k in ehat_pre_ink ehat_pre_emp   {
	rdplot `k' days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 1994, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Value covariate") xtitle("Running variable") xline(79, lcolor(gs8))), 
	graph export "$output/img/rdplot_1994_`k'.pdf", replace
}


* Countries of origin * 
foreach k in africa asia europe southam {
	
	*1994*
	rdplot `k' days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 1994, ///
	graph_options(legend(off)graphregion(color(white))title()ytitle("Value covariate") xtitle("Running variable") xline(79, lcolor(gs8))), 
	graph export "$output/img/rdplot_1994_`k'.pdf", replace
	
	*2010*
	rdplot `k' days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 2010, ///
	graph_options(legend(off)graphregion(color(white))title()ytitle("Value covariate") xtitle("Running variable") xline(30, lcolor(gs8))), 
	graph export "$output/img/rdplot_2010_`k'.pdf", replace
}

replace days_treat_enrolled = days_treat_enrolled * (-1)						// Changing back


** Regressions **

*1994 - 79 days
eststo clear		
eststo col1: rdrobust age days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform) 	
eststo col2: rdrobust bigcity days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     
eststo col3: rdrobust children days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform) 
eststo col4: rdrobust ehat_yeduc  days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     
eststo col5: rdrobust ehat_pre_ink days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     
eststo col6: rdrobust ehat_pre_emp days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     
eststo col7: rdrobust welf days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     

esttab col1 col2 col3 col4 col5 col6 col7 using "$output/tex/Balance_1994_7979.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab


*1994 - 50 days
eststo clear		
eststo col1: rdrobust age days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform) 
eststo col2: rdrobust bigcity days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform)     
eststo col3: rdrobust children days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform) 
eststo col4: rdrobust ehat_yeduc days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform)     
eststo col5: rdrobust ehat_pre_ink days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform)     
eststo col6: rdrobust ehat_pre_emp days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform)     
eststo col7: rdrobust welf days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform)     

esttab col1 col2 col3 col4 col5 col6 col7 using "$output/tex/Balance_1994_5050.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab
	
*1994 - 30 days
eststo clear		
eststo col1: rdrobust age days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform) 
eststo col2: rdrobust bigcity days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform)     
eststo col3: rdrobust children days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform) 
eststo col4: rdrobust ehat_yeduc days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform)     
eststo col5: rdrobust ehat_pre_ink days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform)     
eststo col6: rdrobust ehat_pre_emp days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform)     
eststo col7: rdrobust welf days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform)     

esttab col1 col2 col3 col4 col5 col6 col7 using "$output/tex/Balance_1994_3030.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab


*2010 - 30/79 days *
eststo clear		
eststo col1: rdrobust age days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform) 	
eststo col2: rdrobust bigcity days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform)     
eststo col3: rdrobust children days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform) 
eststo col4: rdrobust ehat_yeduc days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform)     
eststo col5: rdrobust ehat_pre_ink days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform)     
eststo col6: rdrobust ehat_pre_emp days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform)     
eststo col7: rdrobust welf days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform)     

esttab col1 col2 col3 col4 col5 col6 col7 using "$output/tex/Balance_2010_7930.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab

*2010 - 30/50
eststo clear		
eststo col1: rdrobust age days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform) 	
eststo col2: rdrobust bigcity days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform)     
eststo col3: rdrobust children days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform) 
eststo col4: rdrobust ehat_yeduc days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform)     
eststo col5: rdrobust ehat_pre_ink days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform)     
eststo col6: rdrobust ehat_pre_emp days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform)     
eststo col7: rdrobust welf days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform)     

esttab col1 col2 col3 col4 col5 col6 col7 using "$output/tex/Balance_2010_5050.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab

*2010 - 30/30
eststo clear		
eststo col1: rdrobust age days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col2: rdrobust bigcity days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform)     
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col3: rdrobust children days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col4: rdrobust ehat_yeduc days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform)     
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col5: rdrobust ehat_pre_ink days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col6: rdrobust ehat_pre_emp days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col7: rdrobust welf days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"

esttab col1 col2 col3 col4 col5 col6 col7 using "$output/tex/Balance_2010.tex", stats(N_h_l N_h_r func vikt covars, fmt(0 0 0 0 0 0) ///
label("Obs, below cut-off" "Obs, above cut-off" "Functional form" "Kernel" "Covariates")) $esttab



///NOW FOR COUNTRY OF ORIGIN

*1994 - 79 days
eststo clear		
eststo col1: rdrobust africa days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform) 	
eststo col2: rdrobust asia days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform) 
eststo col3: rdrobust europe days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     
eststo col4: rdrobust southam days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(79) kernel(uniform)     

esttab col1 col2 col3 col4 using "$output/tex/Balance_ifau_1994_7979.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab

	
*1994 - 50 days
eststo clear		
eststo col1: rdrobust africa days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform) 
eststo col2: rdrobust asia days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform) 
eststo col3: rdrobust europe days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform)     
eststo col4: rdrobust southam days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(50) kernel(uniform)     

esttab col1 col2 col3 col4 using "$output/tex/Balance_ifau_1994_5050.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab
	
*1994 - 30 days
eststo clear		
eststo col1: rdrobust africa days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform) 
eststo col2: rdrobust asia days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform) 
eststo col3: rdrobust europe days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform)     
eststo col4: rdrobust southam days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1994, h(30) kernel(uniform)     

esttab col1 col2 col3 col4 using "$output/tex/Balance_ifau_1994_3030.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab


*2010 - 30/79 days *
eststo clear		
eststo col1: rdrobust africa days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform) 	
eststo col2: rdrobust asia days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform) 
eststo col3: rdrobust europe days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform)     
eststo col4: rdrobust southam days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 79) kernel(uniform)     

esttab col1 col2 col3 col4 using "$output/tex/Balance_ifau_2010_7930.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab

*2010 - 30/50
eststo clear		
eststo col1: rdrobust africa days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform) 	
eststo col2: rdrobust asia days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform) 
eststo col3: rdrobust europe days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform)     
eststo col4: rdrobust southam days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 50) kernel(uniform)     

esttab col1 col2 col3 col4 using "$output/tex/Balance_ifau_2010_5050.tex", nonum nomti ///
stats(N_h_l N_h_r, fmt(0 0) ///
label("Obs, below cut-off" "Obs, above cut-off")) $esttab

*2010 - 30/30
eststo clear		
eststo col1: rdrobust africa days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col2: rdrobust asia days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col3: rdrobust europe days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform)     
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"
eststo col4: rdrobust southam days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2010, h(30 30) kernel(uniform) 
estadd local func "Linear"
estadd local vikt "Uniform"
estadd local covars "No"

esttab col1 col2 col3 col4 using "$output/tex/Balance_ifau_2010.tex", stats(N_h_l N_h_r func vikt covars, fmt(0 0 0 0 0 0) ///
label("Obs, below cut-off" "Obs, above cut-off" "Functional form" "Kernel" "Covariates")) $esttab






********************************************************************************
* Novelty analysis ************************************************************
********************************************************************************

use "$usingdata/noveltyanalysis", clear												// All the rest generated before the datamanagement for spouse-data

*
order LopNr voted_local
compress
save "$usingdata/finaldata/finaldata_immigrants_rev.dta", replace

replace days_treat_enrolled=days_treat_enrolled * (-1)							// See comment above
replace days_treat_citizen=days_treat_citizen * (-1)							


* Esttab setup*
global esttab "replace label se nogaps b(3) compress nostar booktabs nonotes varlabels(_cons "Constant")"

** Eligibility graphs according to Calonico et al (2015) **

* 1991, with donut*
rdplot eligeble days_treat_enrolled if (days_treat_enrolled > 0 | days_treat_enrolled <-7) & year_ctz == 1991, ///
graph_options(name(g1, replace) legend(off)graphregion(color(white)) title("") ytitle("Eligibility") xtitle("Running variable") xline(79, lcolor(gs8)))
graph export "$output/img/rdplot_eligibility1991_1.pdf", replace

* 2006, with donut *
rdplot eligeble days_treat_enrolled if (days_treat_enrolled > 0 | days_treat_enrolled <-7) & year_ctz == 2006,  ///
graph_options(name(g2, replace) legend(off)graphregion(color(white)) title("") ytitle("Eligibility") xtitle("Running variable") xline(30, lcolor(gs8)))
graph export "$output/img/rdplot_eligibility2006_1.pdf", replace


* RD-plot according to Calonico et al (2015): Only salience, 1991
rdplot voted_local days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 1991, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout") xtitle("Running variable") xline(79, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_1991.pdf", replace

* [...] Only salience, 2010 *
rdplot voted_local days_treat_enrolled if (days_treat_enrolled >= 0 | days_treat_enrolled <-7) & year_ctz == 2006, ///
graph_options(legend(off)graphregion(color(white))title()ytitle("Voter turnout") xtitle("Running variable") xline(30, lcolor(gs8))), 
graph export "$output/img/rdplotT2T3_2006.pdf", replace


* 1991*
clear matrix
forvalues k = 11(1)79 {															// OBS: 10 including the donut equals a window of 3 days of the running variable above the cut-off. 	
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 1991, h(`k') kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												// Conventional standard errors												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1, lpattern(dash) lcolor(gs8)) (line rd4 rd1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) ylabel(-0.4(0.1)0.4) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Symmetric bandwidth in days")
graph export "$output/img/novelty_bandbreddgraf_1991.pdf", replace 
restore
drop rd*


* 2006 *
clear matrix
forvalues k = 11(1)79 {															/*Observe that we vary the upper bandwidth in the case of 2010. The lower bandwidth cannot be larger than 30*/
	preserve
	rdrobust voted_local days_treat_enrolled if (days_treat_enrolled > 7 | days_treat_enrolled <=0) & year_ctz == 2006, h(30 `k') kernel(uniform)     
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1											
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd=[nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1, lpattern(dash) lcolor(gs8)) (line rd4 rd1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(7(6)79) ylabel(-0.2(0.1)0.2) legend(order(1 "Point estimate sharp RD" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Asymmetric bandwidth in days, above cut-off")
graph export "$output/img/novelty_bandbreddgraf_2006.pdf", replace 
restore
drop rd*




***
capture log close
clear all
